<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>历史记录查询</title>
    <script src="${pageContext.request.contextPath}/static/jquery/jquery-3.1.1.js"></script>
    <script src="${pageContext.request.contextPath}/static/jquery/jquery.validate.js"></script>
    <link rel="stylesheet" href="/static/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/static/frame/static/css/style.css">
    <link rel="icon" href="/static/frame/static/image/code.png">
</head>
<body>
<div>
    <form action="recordListByUser.do" method="post" style="float:left;margin:20px">
        <input type="text" name="record_user_name" style="height: 40px;padding-left:5px;font-size: 16px" class="selectbox" placeholder="用户姓名 / Name"/>
        <input type="submit" style="padding-top: 7px;padding-bottom: 9px" value="查询用户姓名" class="selectbutton"/>
    </form>
    <form action="recordListByDate.do" method="post" style="float: left;margin-top: 20px;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" style="height: 41px;padding-left:5px;font-size: 16px"  name="record_passtime" id="date" lay-verify="date" placeholder="查询日期" autocomplete="off" class="layui-input">
                </div>
                <input type="submit" style="padding-top: 6px;padding-bottom: 8px;padding-left: 15px;padding-right: 15px" value="查询" class="selectbutton"/>
            </div>
        </div>
    </form>
</div>
<div style="float: left;margin-top: 30px;">(左侧两个查询输入为空时，查询结果为全部门禁通过历史记录)</div>
    <div class="showmessages">
        <table class="layui-table">
            <thead>
            <tr>
                <th style="width: 160px;">历史记录ID</th>
                <th style="width: 160px;">用户姓名</th>
                <th style="width: 160px;">所属业主名</th>
                <th style="width: 160px;">住所</th>
                <th style="width: 260px;">通过时间</th>
            </tr>
            </thead>
            <tbody id="clear" style="display: none">
            <script>var arr1=[]</script>
            <c:if test="${not empty sessionScope.recordList}">
            <c:forEach items="${sessionScope.recordList}" var="o" varStatus="loop">
                <tr id="recorder${loop.count}">
                    <td>${o.getRecord_id()}</td>
                    <td>${recordUser[loop.count-1].user_name}</td>
                    <td>${recordHost[loop.count-1].host_name}</td>
                    <td>${recordHost[loop.count-1].host_building}栋${recordHost[loop.count-1].host_unit}单元${recordHost[loop.count-1].host_housenumber}号</td>
                    <td class="passtime">${o.getRecord_passtime()}</td>
                </tr>
                <script>arr1.push($("#recorder${loop.count}")[0])</script>
            </c:forEach>
            </c:if>
            </tbody>
            <tbody id="biuuu_city_list"></tbody>
        </table>
        <div id="demo20"></div>
    </div>
</body>
<script src="${pageContext.request.contextPath}/static/frame/layui/layui.js" charset="utf-8"></script>
<script>
    function nodeToString ( node ) {
        var tmpNode = document.createElement( "div" );
        tmpNode.appendChild( node.cloneNode( true ) );
        var str = tmpNode.innerHTML;
        tmpNode = node = null; // prevent memory leaks in IE
        return str;
    }
    function clear(){
        document.getElementById('clear').innerHTML=null;
    }
    layui.use(['form', 'layedit', 'laydate','carousel', 'laypage','jquery'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,$=layui.jquery
            ,upload = layui.upload
            ,laypage = layui.laypage

        var data1= arr1;
        laypage.render({
            elem: 'demo20'
            ,count: data1.length
            ,jump: function(obj){
                //模拟渲染
                document.getElementById('biuuu_city_list').innerHTML = function(){
                    var arr = []
                        ,thisData = data1.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
                    layui.each(thisData, function(index, item){
                        var itemstr=nodeToString(item);
                        arr.push(itemstr);
                    });
                    clear();
                    return arr.join('');
                }();
            }
        });
        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

    });
</script>
<script>
    var w=$(window).width();
    var h=$(window).height();
    $(".pageall").innerHeight(h+"px");
    $(".pageall").innerWidth(w+"px");
    /**
     * 时间显示，调整格式
     */
    showtime();
    function showtime() {
        var passtime=$(".passtime");
        passtime.each(function () {
            //调用时间格式转换函数formatDateTime()
            $(this).text(formatDateTime($(this).text()))
        });
    }
    /**
     *
     * 在页面上，转换时间格式
     * @param inputTime
     * @returns {string}
     */
    function formatDateTime(inputTime) {
        var date = new Date(inputTime);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    };
</script>
</html>